const modules = import.meta.glob('./../views/**/**/index.vue')

const ABSOLUTE_PATH = '/@/views'
const RELATIVE_PATH = '../views'
export const generateRoutes = routes => {
    const result = []
    if (routes && routes.length > 0) {
        for (let i = 0; i < routes.length; i++) {
            const component = routes[i].component ? routes[i].component.replace(ABSOLUTE_PATH, RELATIVE_PATH) : null
            if (component && modules[component]) {
                result.push({
                    path: routes[i].url,
                    name: routes[i].name,
                    component: modules[component]
                })
            }
        }
    }
    return result
}

export const pushRoute = (router, parentRoute, routes) => {
    if (routes && routes.length > 0) {
        routes.forEach(route => {
            router.addRoute(parentRoute, route)
        })
    }
}
